import {Injectable} from '@angular/core';
import * as $ from 'jquery';

@Injectable({
  providedIn: 'root'
})
export class Util {

  /**
   * compare project menu property
   * @param property
   * @param isLetter
   */
  public static compare(property, isLetter: boolean = false) {
    if (isLetter) {
      return (a, b) => {
        let result = a[property].toLowerCase() > b[property].toLowerCase() ? 1 : -1;
        if (!a.isLeaf && b.isLeaf) { result = -1; }
        if (a.isLeaf && !b.isLeaf) { result = 1; }
        return result;
      };
    } else {
      return (a, b) => {
        const value1 = a[property];
        const value2 = b[property];
        return value1 - value2;
      };
    }
  }

  /**
   * show mask
   */
  showMask() {
    setTimeout(() => {
      $('.load-mask').show();
    });
  }

  /**
   * hide mask
   */
  hideMask() {
    setTimeout(() => {
      $('.load-mask').hide();
    });
  }
}
